<template>
<h2>等级新增</h2>
<table class="table table-bordered">
    <tr>
        <td>等级名称</td>
        <td>
            <input type="text" v-model="info.levelname"/>
        </td>
    </tr>
    <tr>
        <td>最小积分</td>
        <td>
            <input type="text" v-model="info.minjing"/>
        </td>
    </tr>
    <tr>
        <td>最大积分</td>
        <td>
            <input type="text" v-model="info.maxjing"/>
        </td>
    </tr>
    <tr>
        <td colspan="2">
            <input type="button" value="添加" class="btn btn-info" @click="Add" />
        </td>
    </tr>
</table>
</template>

<script setup lang="ts">
import {ref} from 'vue'
import axios from 'axios'
import { useRouter } from 'vue-router';
const router=useRouter()

const info=ref({
    levelname:'',
    maxjing:'',
    minjing:'',
    createtime:new Date()
})

const Add=()=>{
    var obj={
        levelname:info.value.levelname,
        maxjing:info.value.maxjing,
        minjing:info.value.minjing,
        createtime:info.value.createtime
    }
    if(!obj.levelname){
        alert('等级名称不能为空')
        return
    }
    if(!obj.maxjing){
        alert('最大积分不能为空')
        return
    }
    if(!obj.minjing){
        alert('最小积分不能为空')
        return
    }
    axios.post('https://localhost:7279/api/LevelLevelAdd',obj)
    .then(res=>{
        if(res.data==-1){
            alert('等级名称不能重复')
        }
        else if(res.data>0){
            alert('添加成功')
            router.push('/LevelShow')
        }
        else{
            alert('添加失败')
        }
    })
    .catch(err=>{
        console.log(err)
    })
}


</script>